package com.wesley.growth.quartz.controller;

import com.wesley.growth.quartz.config.JobInit;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * JobManagementController
 *
 * @author WangPanYong
 * @since 2021/04/12 16:02
 */
@RestController
public class JobManagementController{

    @Autowired
    private Scheduler scheduler;

    @PostMapping(value = "/jobs/stop")
    public String stopJob(String id) {
        try {
            scheduler.unscheduleJob(TriggerKey.triggerKey(id));
            scheduler.getSchedulerName();
            JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(JobInit.ID + "01"));
            return jobDetail.getDescription();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }

        return "Null";
    }


}
